<?php
/**
 * Created by PhpStorm.
 * User: syzhou
 * Date: 2020-11-12
 * Time: 17:39
 */

require_once __DIR__ . '/common.php';

global $uploadedFilePathsSavePath;
global $distinctUploadedFileSaveDirSavePath;

$uploadedFilePaths = file($uploadedFilePathsSavePath, FILE_IGNORE_NEW_LINES);
$uploadedFileSaveDirPrefixLen = strlen('/upload/20190621/66A8B18A-11E3-EF7C-F273-178F9C630D21');
$distinctUploadedFileSaveDirSet = [];
foreach ($uploadedFilePaths as $uploadedFilePath) {
    $uploadedFileSaveDir = substr($uploadedFilePath, 0, $uploadedFileSaveDirPrefixLen);
    $distinctUploadedFileSaveDirSet[$uploadedFileSaveDir] = null;
}
$distinctUploadedFileSaveDirs = array_keys($distinctUploadedFileSaveDirSet);
$fh = fopen($distinctUploadedFileSaveDirSavePath, 'w');
foreach ($distinctUploadedFileSaveDirs as $uploadedFileSaveDir) {
    fwrite($fh, "$uploadedFileSaveDir\n");
}
fclose($fh);